package chen.yi.web.controller;

import chen.yi.common.resp.R;
import chen.yi.component.code.generator.actuator.CodeActuator;
import chen.yi.component.code.generator.service.element.ElementInfoService;
import chen.yi.mapper.base.BasePO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;


/**
 * 代码生成器接口
 * @author huat
 **/
@RestController
@RequestMapping("/generator")
public class GeneratorController {
    private final CodeActuator codeActuator;
    private final ElementInfoService elementInfoService;

    @Autowired
    public GeneratorController(CodeActuator codeActuator, ElementInfoService elementInfoService) {
        this.codeActuator = codeActuator;
        this.elementInfoService = elementInfoService;
    }

    /**
     * 获取po
     */
    @GetMapping("/getPO")
    public String getPO(@RequestParam("tableName") String tableName){

        return codeActuator.getEntityCode(tableName);
    }
    /**
     * 获取po
     */
    @GetMapping("/getMapper")
    public String getMapper(@RequestParam("tableName") String tableName){

        return codeActuator.getMapperCode(tableName);
    }
    /**
     * 获取service
     */
    @GetMapping("/getService")
    public String getService(@RequestParam("tableName") String tableName){

        return codeActuator.getServiceCode(tableName);
    }
    /**
     * 获取serviceImpl
     */
    @GetMapping("/getServiceImpl")
    public String getServiceImpl(@RequestParam("tableName") String tableName){

        return codeActuator.getServiceImplCode(tableName);
    }
    /**
     * 获取controller
     */
    @GetMapping("/getController")
    public String getController(@RequestParam("tableName") String tableName){

        return codeActuator.getControllerCode(tableName);
    }
    @GetMapping("/getElement")
    public R getElement(@RequestParam("terminal") String terminal){
        return R.success(elementInfoService.getAllElementInfo(terminal));
    }
}
